#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
 struct TreeNode {
         int val;
         TreeNode *left;
         TreeNode *right;
         TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     };

bool isSameTree(TreeNode* p, TreeNode* q) {
    if(p== nullptr &&q!= nullptr)return false;
    if(p!= nullptr &&q== nullptr)return false;
    if(p== nullptr&&q== nullptr)return true;
    return (p->val == q->val) && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
}

int main(){
    TreeNode* a = new TreeNode(1);
    TreeNode* temp = a;
    temp->left = new TreeNode(2);
    temp->right = new TreeNode(3);

    TreeNode*b = new TreeNode(1);
    temp = b;
    temp->left = new TreeNode(2);
    temp->right = new TreeNode(3);

    cout<<isSameTree(a,b);
    return 0;
}